package distributedbank;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

import distributedbank.client.ClientUI;
import distributedbank.responses.Response;
/**
 * Used to listen to Responses
 * on ClientUIs
 */
public class ResponseThread extends Thread{
	private ClientUI clientUI;
	private Socket incomingSocket;
	public ResponseThread(ClientUI cUI, Socket clientSocket){
		this.clientUI = cUI;
		this.incomingSocket = clientSocket;
	}
	public void run(){
		try{
			ObjectInputStream in = new ObjectInputStream(
						incomingSocket.getInputStream());
			Response response = null;
			try {
				response = (Response)in.readObject();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			response.runResponse(clientUI);
			in.close();
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
	}
}
